<template>
	<view>
		<view class="relative">
			<image src="https://gsconline-1251028293.cos.ap-guangzhou.myqcloud.com/images/2020/05/19/image_158987206310210097.png" mode="widthFix" class="w100"></image>
			<view class="absolute statistics_view">
				<cu-custom :isBack="true" style="color: #FFF !important;">
					<block slot="backText"></block>
					<block slot="content"><text>消费明细</text></block>
					<block slot="right">
						<view class="margin-right" style="line-height:16px;display: flex;align-items: center;justify-content: center; height: 100%;">时间筛选</view>
					</block>
				</cu-custom>
				<view class=" text-white text-center">
					<view class="text-xxxl margin-top">
						{{statistics?statistics.credits_order:0}}
					</view>
					<view class="">总消费</view>
				</view>
			</view>
		</view>

		<view class="relative w100">
			<view class="absolute objlist w100 padding-lr">
				<view class="bg-white margin-top radius" v-for="(item,index) in list" :key="index" v-if="item.order">
					<view class="w100 padding-bottom padding-top-sm">
						<block v-if="item.order.goods">
							<view v-for="(goods, i) in item.order.goods" :key="i" class="goods_list margin-lr">
								<orderGoods :value="goods"></orderGoods>
							</view>
						</block>
						<view class="space-between padding-lr solid-top-sm margin-top-sm" v-if="item.order">
							<view><text>合计：</text><text class="text-red">{{Math.ceil(item.order.order_amount)}}积分</text></view>
							<view class="text-gray">{{$common.timeFormat(item.created_at)}}</view>
						</view>
					</view>
				</view>
				<view class="cu-load margin-center" :class="loading?'loading':'over'"></view>
			</view>
		</view>
	</view>
</template>

<script>
	import orderGoods from '@/components/shop/orderGoods.vue'
	import Cubar from '@/components/default/Cubar.vue'
	import {
		mapState
	} from 'vuex'
	export default {
		components: {
			orderGoods,
			Cubar
		},
		computed: mapState(['forcedLogin', 'hasLogin', 'channelLogin']),
		data() {
			return {
				statistics: null,
				TabCur: 0,
				member: null,
				list: [],
				hasMore: true,
				page: 1,
				loading: false,
			}
		},
		onLoad() {
			if (this.$common.loginAuth(true)) {
				this.$common.getMember().then((member) => {
					this.member = member
					let statictics = this.$common.getCache('credit_statictics')
					if (!statictics) {
						this.$nextTick((r) => {
							uni.startPullDownRefresh({})
						})
					} else {
						this.statistics = statictics
						this.getList()
					}
				})
			}
		},
		onShow() {
			this.$common.loginAuth(true)
		},
		methods: {
			getInfo() {
				this.$http
					.get('integral_info', {})
					.then((response) => {
						this.statistics = response.data.data
						this.$common.setCache('credit_statictics', this.statistics, 10 * 60)
						uni.hideLoading()
						uni.stopPullDownRefresh()
					})
					.catch((response) => {
						console.log(response)
					})
			},
			getList() {
				if (this.hasMore) {
					this.loading = true
					this.$http
						.get('integral_details', {
							page: this.page,
							group_type:4
						})
						.then((response) => {
							let list = this.list
							if (response.data.data.length > 0) {
								list = list.concat(response.data.data)
							} else {
								this.hasMore = false
							}
							this.list = list
							this.loading = false
							this.page += 1
						})
						.catch((response) => {
							console.log(response)
							this.loading = false
						})
				}
			},
		},
		onReachBottom() {
			this.getList()
		},
		onPullDownRefresh() {
			this.getInfo()
			this.list = []
			this.hasMore = true
			this.page = 1
			this.loading = false
			this.getList()
		},
	}
</script>

<style>
	.relative {
		position: relative;
	}

	.absolute {
		position: absolute;
	}

	.statistics_view {
		left: 0;
		top: 0;
		width: 100%;
	}

	.text-xxxl {
		font-size: 80rpx;
	}

	.btnr {
		border-radius: 40rpx 0 0 40rpx;
		padding: 0 40rpx;
		height: 50rpx;
	}

	.m-title {
		font-size: 32rpx !important;
		position: relative;
		display: block;
	}

	.m-title::after {
		content: "";
		left: 0;
		position: absolute;
		width: 70rpx;
		height: 4rpx;
		bottom: 0;
		background-color: #ffb03a;
		z-index: 0;
	}

	.mfixed {
		width: 100%;
		top: 0;
	}

	.objlist {
		top: -140rpx;
	}

	.goods-thumb {
		width: 180rpx;
		height: 180rpx;
		min-width: 180rpx;
	}

	.goods-thumb image {
		width: 100%;
		height: 100%;
	}
</style>
